#include <stdio.h>
#include<iostream>
using namespace std;
void InsertionSort(int a[], int n)
{
  for(int j = 1; j < n; j++)
  {
    int key = a[j];
    int i = j - 1;
    while(i >= 0 && key < a[i])
    {
      a[i + 1] = a[i];
      i--;
    }
    a[i + 1] = key;
  }
}

int main(int argc, char const *argv[])
{
  int d[] = { 12, 15, 9, 20, 6, 31, 24};
  cout << "输入数组  { 12, 15, 9, 20, 6, 31, 24 } " << endl;
  InsertionSort(d, 7);
  cout << "排序后结果：";
  for (int i = 0; i < 7; i++)
  {
      cout << d[i]<<" ";
  }
  return 0;
}
